const mysql = require('mysql')//引入mysql模块
const connection = mysql.createConnection({//配置参数信息
    host:'localhost',
    user:'root',
    password:'12345',
    database:'census'
})

connection.connect();//进行连接
var  sql = 'SELECT * FROM diagnosislist';
// 查
// connection.query(sql,function (err, result) {
//         if(err){
//           console.log('[SELECT ERROR] - ',err.message);
//           return;
//         }
 
//        console.log('--------------------------SELECT----------------------------');
//        console.log(result);
//        console.log('------------------------------------------------------------\n\n');  
// });

var  addSql = 'INSERT INTO diagnosislist(id,name,idCardNo,sex,address,phoneNumber,myDesc,source) VALUES(0,?,?,?,?,?,?,?)';
var  addSqlParams = ['唐悠悠', '372926197501010355','男','北京市通州区科谷一街','15632458976','备注信息','境外输入'];
//增
// let data=[
//     name= '````````````````',
//     idCardNo= '372926197501010355',
//     sex= '男',
//     address= '无家可归',
//     phoneNumber= '2345678',
//     myDesc= '无',
//     source= '本地',
//     id=15
// ]
// connection.query(addSql,data,function (err, result) {
//         if(err){
//          console.log('[INSERT ERROR] - ',err.message);
//          return;
//         }        
 
//        console.log('--------------------------INSERT----------------------------');
//        //console.log('INSERT ID:',result.insertId);        
//        console.log('INSERT ID:',result);        
//        console.log('-----------------------------------------------------------------\n\n');  
// });

var modSql = 'UPDATE diagnosislist SET name = ?,idCardNo = ?,sex = ?,address = ?,phoneNumber = ?,myDesc = ?,source = ? WHERE id = ?';
var modSqlParams = ['我是15', '372926197501010355','不男不女','123','1245678765','没有','境外',15];
//改
// let data=[
//     name= '咔咔',
//     idCardNo= '372926197501010355',
//     sex= '男',
//     address= '无家可归',
//     phoneNumber= '2345678',
//     myDesc= '无',
//     source= '本地',
//     id=15
// ]
// connection.query(modSql,data,function (err, result) {
//    if(err){
//          console.log('[UPDATE ERROR] - ',err.message);
//          return;
//    }        
//   console.log('--------------------------UPDATE----------------------------');
//   console.log('UPDATE affectedRows',result.affectedRows);
//   console.log('-----------------------------------------------------------------\n\n');
// });

var delSql = 'DELETE FROM diagnosislist where id=18,19';
//删
connection.query(delSql,function (err, result) {
        if(err){
          console.log('[DELETE ERROR] - ',err.message);
          return;
        }        
 
       console.log('--------------------------DELETE----------------------------');
       console.log('DELETE affectedRows',result.affectedRows);
       console.log('-----------------------------------------------------------------\n\n');  
});
connection.end()//关闭连接
